package site.marqstree.kotlinmall.ui.fragment.home.topic

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.viewpager.widget.PagerAdapter
import kotlinx.android.synthetic.main.item_home_topic.view.*
import org.jetbrains.anko.imageURI
import site.marqstree.kotlin.library.base.ui.widget.roundrectimage.RoundRectImageView
import site.marqstree.kotlin.library.base.util.GlideUtil
import site.marqstree.kotlinmall.R


/*
 * 项目名: KotlinMall
 * 包名: site.marqstree.kotlinmall.ui.fragment.home.topic
 * 文件名: TopicAdapter
 * 创建者: marqstree
 * 创建时间: 2020/3/3 17:29
 * 描述: 话题数据适配器
 */
class TopicAdapter(private val context: Context, private val list: List<String>) : PagerAdapter() {

    override fun destroyItem(parent: ViewGroup, paramInt: Int, paramObject: Any) {
        parent.removeView(paramObject as View)
    }

    override fun getCount(): Int {
        return this.list.size
    }

    override fun instantiateItem(parent: ViewGroup, position: Int): Any {
        val rooView = LayoutInflater.from(this.context).inflate(R.layout.item_home_topic, null)
        GlideUtil.loadImage(context,
                    list[position],
                    rooView.mTopicIv)
        parent.addView(rooView)
        return rooView
    }

    override fun isViewFromObject(paramView: View, paramObject: Any): Boolean {
        return paramView === paramObject
    }
}